package com.yxuan.springboot.util;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.yxuan.springboot.model.UserLogin;
import io.jsonwebtoken.Claims;

public class ResolveTokenUtil {




    /**
     *  //获取token中手机号并查询该手机号对应的用户专用方法
     * @param token
     * @return
     * @throws Exception
     */
    public static UserLogin targetLogin(String token) throws Exception {


        Claims claims = JwtUtil.parseJWT(token);
        String sub = claims.get("sub", String.class);
        JsonNode subNode = new ObjectMapper().readTree(sub);
        String phoneNumber = subNode.get("phoneNumber").asText();
        //设置用户手机号，静态方法里不能自动注入，所以不能用loginService.login()查询到手机号指定用户
        UserLogin newLogin = new UserLogin();
        newLogin.setPhoneNumber(phoneNumber);
        //返回的是一个设置好了手机号的Login对象
        return newLogin;
    }



}
